﻿using BLL;
using IBLL;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using user_defined_Panl;

namespace WindowsFormsApp1.登录老师账号界面
{
    public partial class FrmQuestionBank : Form
    {
        public  FlowLayoutPanel[] layoutPanel = null;
        IFrQuestionBankManage_IBLL frQuestion = new FrQuestionBankManage_BLL();
        FrmQuestionBank_BLL frm=new FrmQuestionBank_BLL();
       
        public FrmQuestionBank()
        {

             InitializeComponent();
            int index = 1;
            SqlDataReader sqlData = frQuestion.Query();
            if (sqlData != null)
            {
                while (sqlData.Read())
                {

                    flowLayoutPanel1.Controls.Add(new FlowLayoutPanel_2(new MultipleChoice()
                    {
                        MCID = sqlData["SCID"].ToString(),
                        Topic = sqlData["Topic"].ToString(),
                        Answer = sqlData["Answer"].ToString(),
                        A = sqlData["A"].ToString(),
                        B = sqlData["B"].ToString(),
                        C = sqlData["C"].ToString(),
                        D = sqlData["D"].ToString(),
                        Score = sqlData["Score"].ToString()
                    }, index.ToString(), true, false));
                    index++;
                }
                index = 1;
                if (sqlData.NextResult())
                {
                    while (sqlData.Read())
                    {
                        flowLayoutPanel2.Controls.Add(new FlowLayoutPanel_2(new MultipleChoice()
                        {
                            MCID = sqlData["MCID"].ToString(),
                            Topic = sqlData["Topic"].ToString(),
                            Answer = sqlData["Answer"].ToString(),
                            A = sqlData["A"].ToString(),
                            B = sqlData["B"].ToString(),
                            C = sqlData["C"].ToString(),
                            D = sqlData["D"].ToString(),
                            Score = sqlData["Score"].ToString()
                        }, index.ToString()));
                        index++;
                    }
                }
                index = 1;
                if (sqlData.NextResult())
                {
                    while (sqlData.Read())
                    {
                        flowLayoutPanel3.Controls.Add(new FlowLayoutPanel_3(new TrueOrFalseQuestions()
                        {
                            SPID = sqlData["SPID"].ToString(),
                            Topic = sqlData["Topic"].ToString(),
                            Answer = sqlData["Answer"].ToString(),
                            Score = sqlData["Score"].ToString()
                        }, index.ToString()));
                        index++;
                    }
                }
                index = 1;
                if (sqlData.NextResult())
                {
                    while (sqlData.Read())
                    {
                        flowLayoutPanel4.Controls.Add(new FlowLayoutPanel_4(new Completion()
                        {
                            CPID = sqlData["CPID"].ToString(),
                            Topic = sqlData["Topic"].ToString(),
                            Answer = sqlData["Answer"].ToString(),
                            Score = sqlData["Score"].ToString(),
                            ScoringPoint = sqlData["ScoringPoint"].ToString()
                        }, index.ToString()));
                        index++;
                    }
                }
                sqlData.Close();
            }


        }

        private void butReturn_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void AddStudentss_Click(object sender, EventArgs e)
        {
            layoutPanel = FrAddExam.layoutPanel;
            int a= flowLayoutPanel1.Controls.Count;
            for (int i = 0; i < a; i++)
            {
               
                if ((flowLayoutPanel1.Controls[i].Controls[0] as CheckBox).Checked==true)
                {
                    layoutPanel[0].Controls.Add(flowLayoutPanel1.Controls[i]);
                    i--;
                    a--;
                 
                } 
            }
            a = flowLayoutPanel2.Controls.Count;
            for (int i = 0; i < a; i++)
            {

                if ((flowLayoutPanel2.Controls[i].Controls[0] as CheckBox).Checked == true)
                {
                    layoutPanel[1].Controls.Add(flowLayoutPanel2.Controls[i]);
                    i--;
                    a--;

                }
            }
            a = flowLayoutPanel3.Controls.Count;
            for (int i = 0; i < a; i++)
            {

                if ((flowLayoutPanel3.Controls[i].Controls[0] as CheckBox).Checked == true)
                {
                    layoutPanel[2].Controls.Add(flowLayoutPanel3.Controls[i]) ;
                    i--;
                    a--;

                }
            }
            a = flowLayoutPanel4.Controls.Count;
            for (int i = 0; i < a; i++)
            {

                if ((flowLayoutPanel4.Controls[i].Controls[0] as CheckBox).Checked == true)
                {
                    layoutPanel[3].Controls.Add(flowLayoutPanel4.Controls[i]);
                    i--;
                    a--;

                }
            }           
        }
    }
}
